import {Dropdown, Icon, Menu} from 'antd';
import Static from './Static'

const AntDropdown = ({items=[], title, onClick}) => {
    const menu = (
        <Menu onClick={onClick}>
            {(items || []).map((item, index) => (
                <Menu.Item key={item.key}>
                    <a target="_blank"
                       rel="noopener noreferrer"
                       href={item.link}
                    >
                        {item.name}
                    </a>
                </Menu.Item>
            ))}
        </Menu>
    );

    return (
        items.length == 0
            ? <Static label={title} fontSize='.875rem' color='#fff'/>
            : <Dropdown overlay={menu}>
                <a className="ant-dropdown-link" href="#" style={{color: '#fff'}}>
                    {(items || []).length > 0 ? title : items[0].name || '无用户'}
                    {(items || []).length > 0 && <Icon type="down"/>}
                </a>
            </Dropdown>
    )
}

export default AntDropdown